<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>增加配件信息</title>
    <link rel="stylesheet" href="<%=basePath %>web/css/from.css">
    <link rel="stylesheet" href="<%=basePath %>web/themes/default/easyui.css">
    <link rel="stylesheet" href="<%=basePath %>web/themes/icon.css">
    <script src="<%=basePath %>web/js/jquery.min.js"></script>
    <script src="<%=basePath %>web/js/jquery.easyui.min.js"></script>
    <script src="<%=basePath %>web/js/easyui-lang-zh_CN.js"></script>
    <script>
    
       //添加
       function modifyPartDetail(){
           if($("#partName").val()==""||$("#partName").val()==null){
                alert("配件名称不能为空！")
                return false;
           }
           if($("#partTypeId").val()==0){
                alert("请选择配件类别！")
                return false;
           }
           if($("#mold").val()==""||$("#mold").val()==null){
                alert("配件型号不能为空！")
                return false;
           }
           if($("#size").val()==""||$("#size").val()==null){
                alert("配件尺寸不能为空！")
                return false;
           }
           var detail=JSON.stringify(serializeJson());
           $.post("/kxmanage/part/modifyPartDetail.json",{"detail":detail},addresult);
       }
       
        //ajax成功
        function addresult(data){
           if(data.result=="success"){
               alert("保存成功！")
               self.parent.addTabs("配件信息管理","goods/partDetailList.jsp");
               self.parent.$("#jxc_tabs").tabs("close","修改配件信息");
               
           }else{
               alert("保存失败！")
           }
        }
        //表单序列化
        function serializeJson(){  
            var serializeObj={};  
            var array=$("#form").serializeArray();  
            var str=$("#form").serialize();  
            $(array).each(function(){  
                if(serializeObj[this.name]){  
                    if($.isArray(serializeObj[this.name])){  
                        serializeObj[this.name].push(this.value);  
                    }else{  
                        serializeObj[this.name]=[serializeObj[this.name],this.value];
                    }  
                }else{  
                    serializeObj[this.name]=this.value;   
                }  
            });  
                return serializeObj;  
            };
        function closeDg(name) {
            $("#supplierName").val(name);
            $("#list").dialog("close");
        }
        function closetabs(){
            self.parent.$("#jxc_tabs").tabs("close","增加配件信息");
        }
        function addtabs(){
            self.parent.$("#jxc_tabs").tabs("close","修改配件信息");
            self.parent.addTabs("增加配件信息","goods/addPartDetail.jsp");
        }
        $(function(){
            //添加配件类别下拉框
            $('#partTypeId').combobox({    
			    url:'/kxmanage/instroageBill/getPartTypeList.json',    
			    valueField:'id',    
			    textField:'typeName',
			    onLoadSuccess:function(){
			        var data=$(this).combobox("getData");
                    for(var i=0;i<data.length;i++){
                        if(data[i]["id"]==$("#defaultTypeId").val()){
                           $(this).combobox("select", data[i]["id"]); 
                        }
                    }
                }      
			});
			//添加配件品牌下拉框
            $('#partBrand').combobox({    
			    url:'/kxmanage/part/getPartTypeListBrand.json?type='+"配件品牌",    
			    valueField:'key',    
			    textField:'key',
			    onLoadSuccess:function(){
			        var data=$(this).combobox("getData");
			        for(var i=0;i<data.length;i++){
                        if(data[i]["key"]==$("#defaultBrand").val()){
                           $(this).combobox("select", data[i]["key"]); 
                        }
                    }
                    
                }      
			});
			//添加配件单位下拉框
            $('#partUnit').combobox({    
			    url:'/kxmanage/part/getPartTypeListUnit.json?type='+"配件单位",    
			    valueField:'key',    
			    textField:'key',
			    onLoadSuccess:function(){
			        var data=$(this).combobox("getData");
			        for(var i=0;i<data.length;i++){
                        if(data[i]["key"]==$("#defaultUnit").val()){
                           $(this).combobox("select", data[i]["key"]); 
                        }
                    }
                    
                }   
			});
            
           //添加入库类型下拉框
           $.post("/kxmanage/instroageBill/getInstroageType",{"type":"入库方式"},appendInstroageType);
           function appendInstroageType(data){
               for(var i=0;i<data.length;i++){
                   var str="<option value='"+data[i].value+"'>"+data[i].key+"</option>";
                   $("#instroageType").append(str);
               }
           }
           //调整单价和库存
           $("#instroage").change(function(){
               if($("input[type='checkbox']").is(':checked')){
                   $("#amount").removeAttr("readonly");
                   $("#price").removeAttr("readonly");
               }
           })
           
        });
    </script>
    <style>
        body {
            font-size:12px;
            padding:10px
        }
        .l-table-edit {
     	   border-collapse:collapse;border-spacing:0;
        }
        .l-table-edit-td {
            padding:4px;
            font-size:12px;
            border: #84a0c4 1px solid;
        }
        
        input[type='text']{
        	height:20px !important;
        }
        
    </style>


</head>
<body>

<form name="form"  id="form" action="javascript:;" method="post">
    <table cellpadding="0" cellspacing="0" border="1" class="l-table-edit" style="width:100%;margin:10px 0;"  >
        <tr >
            <td width="17%"  align="right" class="l-table-edit-td"><span style="color:red;">*</span>配件编号：</td>
            <td width="27%" align="left" class="l-table-edit-td"><input  type="text" id="code" name="code" value="${part.code }" size="30" maxlength="100" readonly="readonly" ltype="text" /></td>
            <td width="13%"  align="right" class="l-table-edit-td"><span style="color:red;">*</span>配件名称：</td>
            <td width="43%" align="left" class="l-table-edit-td"><input  type="text" id="partName" name="partName"  value="${part.partName }"  maxlength="30" /></td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td"><span style="color:red;">*</span>配件类别：<input type="hidden" id="defaultTypeId" value="${part.partTypeId }"/></td>
            <td align="left" class="l-table-edit-td">
                <select id="partTypeId" class="easyui-combobox" name="partTypeId" style="width:150px;height:25px;"></select></td>
            <td width="17%" align="right" class="l-table-edit-td">配件品牌：<input type="hidden" id="defaultBrand" value="${part.partBrand }"/></td>
            <td align="left" class="l-table-edit-td">
                <select id="partBrand" class="easyui-combobox" name="partBrand" style="width:150px;height:25px;"></select></td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td">件号：</td>
            <td align="left" class="l-table-edit-td"><input  type="text" id="partNo" name="partNo" value="${part.partNo }" size="30" maxlength="50" ltype="text" /></td>
            <td width="17%" align="right" class="l-table-edit-td">通用件号：</td>
            <td align="left" class="l-table-edit-td"><input type="text" id="currPartNo" name="currPartNo" value="${detail.currPartNo }"/></td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td"><span style="color:red;">*</span>型号：</td>
            <td align="left" class="l-table-edit-td"><input  type="text" id="mold" name="mold"  value="${detail.mold }" size="30" maxlength="50" ltype="text" /></td>
            <td width="17%" align="right" class="l-table-edit-td">旧型号：</td>
            <td align="left" class="l-table-edit-td"><input type="text" id="oldMold" value="${detail.oldMold }" name="oldMold"/></td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td"><span style="color:red;">*</span>配件尺寸：</td>
            <td align="left" class="l-table-edit-td"><input  type="text" id="size" name="size"  value="${part.size }" size="30" maxlength="50" ltype="text" /></td>
            <td width="17%" align="right" class="l-table-edit-td">配件重量：</td>
            <td align="left" class="l-table-edit-td"><input type="text" value="${part.weight }" id="weight" name="weight"/></td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td">配件图片：</td>
            <td align="left" class="l-table-edit-td"></td>
            <td width="17%" align="right" class="l-table-edit-td">配件单位：<input type="hidden" id="defaultUnit" value="${part.partUnit }"/></td>
            <td align="left" class="l-table-edit-td">
                <select id="partUnit" class="easyui-combobox" name="partUnit" style="width:150px;height:25px;"></select></td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td">销售价格：</td>
            <td align="left" class="l-table-edit-td"><input  type="text" id="sellPrice" name="sellPrice" value="${part.sellPrice }" size="30" maxlength="50" ltype="text" /></td>
            <td width="17%" align="right" class="l-table-edit-td">显示状态：</td>
            <td align="left" class="l-table-edit-td">
                <input type="radio" name="displayer" <c:if test='${detail.displayer==1 }'>checked</c:if> value="1"/>显示
                <input type="radio" name="displayer" <c:if test='${detail.displayer==2 }'>checked</c:if> value="2"/>隐藏</td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td" valign="top">备注：</td>
            <td align="left" class="l-table-edit-td" colspan="3">
                <textarea  rows="2" name="memo" id="memo" class="l-table-edit" style="width:90%" >${part.memo }</textarea>
            </td>
        </tr>
    </table>
</form>
<br>
<div style="margin-bottom:20px;">
    <input  type="button" onclick="addtabs()" value="新   增" style="width:60px">
	<input  type="button" onclick="modifyPartDetail()" value="保存" style="width:60px">
	<input  type="button" value="打印" style="width:60px">
	<input  type="button" onclick="closetabs()" value="关闭" style="width:60px">
</div>

</body>
</html>